/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package emailtest;

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 *
 * @author Scott
 */
public class EmailTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String host = "imap.gmail.com";
        String username = "srobinson24@gmail.com";
        String password = "xpAA0930?";

        Properties props = System.getProperties();
        props.put("mail.smtp.starttls.enable", "true");
        props.setProperty("mail.store.protocol", "imaps");
        try {
            Session session = Session.getDefaultInstance(props, null);
            Store store = session.getStore("imaps");
            store.connect(host, username, password);           
            MimeMessage message = new MimeMessage(session);
            message.setSubject("Scott's Java Test");
            message.setText("Huzzah, this shit actually works!!!!");
            message.addRecipient(Message.RecipientType.TO, new InternetAddress("srobinson24@gmail.com"));
            
            Transport transport = session.getTransport("smtp");
            transport.connect(host, username, password);
            transport.sendMessage(message, message.getAllRecipients());
            transport.close();

            
        } catch (NoSuchProviderException e) {
            e.printStackTrace();
            System.exit(1);
        } catch (MessagingException e) {
            e.printStackTrace();
            System.exit(2);
        }
        System.out.println("Completed without error");
        //set CLASSPATH=%CLASSPATH%;C:\Program Files\Java\javamail-1.4.4\mail.jar;.
    }
}
